﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.Data.SqlClient;

namespace _24._03.CS
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            this.sqlConnection1.ConnectionString =
                "Integrated Security=SSPI;" +
                "Persist Security Info=False;" +
                "User ID='';" +
                "Initial Catalog=NorthWind;" +
                "Data Source=HP;" +
                "Initial File Name=''";
        }

        private void btnLeggiRecord_Click(object sender, EventArgs e)
        {
            string SQL = 
                "SELECT * FROM Clienti " +
                "WHERE ID < '10'";
            string riga = "";
            this.sqlConnection1.Open();
            SqlCommand Comando = 
                new SqlCommand(SQL, this.sqlConnection1);
            SqlDataReader dr = Comando.ExecuteReader();
            while (dr.Read() != false)
            {
                riga = "Cod. " +
                    dr["ID"].ToString() + " = " +
                    dr["Nome"].ToString() + "  " +
                    dr["Cognome"].ToString();
                this.ListBox1.Items.Add(riga);
            }
            this.sqlConnection1.Close();
            this.Label1.Text = "Lettura terminata!";
        }
    }
}
